package com.example.controller;

import com.example.common.Result;
import com.example.entity.Collect;
import com.example.entity.History;
import com.example.service.HistoryService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * @author: 康伟奇
 * @date: 2024 - 01 - 02 15:40
 **/
/**
 * 浏览历史
 */
@RestController
@RequestMapping("/history")
public class HistoryController {
    @Resource
    private HistoryService historyService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public Result add(@RequestBody History history) {
        historyService.add(history);
        return Result.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        historyService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        historyService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public Result updateById(@RequestBody History history) {
        historyService.updateById(history);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        History history = historyService.selectById(id);
        return Result.success(history);
    }

    /**
     * 查询所有
     */
    @GetMapping("/selectAll")
    public Result selectAll(History history ) {
        List<History> list = historyService.selectAll(history);
        return Result.success(list);
    }

}
